package cn.sdormitory.controller.knowledgebase;

import cn.sdormitory.common.api.CommonResult;
import cn.sdormitory.knowledgebase.pojo.StudyQuestions;
import cn.sdormitory.knowledgebase.service.StudyQuestionsService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Api(tags = "试题库管理模块")
@RequestMapping("/studyQuestions")
public class StudyQuestionsController {

    @Resource
    private StudyQuestionsService studyQuestionsService;

    @ApiOperation("题目列表-分页查询")
    @GetMapping("/getList")
    public CommonResult<IPage<StudyQuestions>> getList(
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(value = "content", required = false) String content,
            @RequestParam(value = "type", required = false) Integer type,
            @RequestParam(value = "category", required = false) Integer category
    ) {
        IPage<StudyQuestions> studyQuestionsIPage = studyQuestionsService.getList(content, type,category, pageNum, pageSize);
        return CommonResult.success(studyQuestionsIPage);
    }

    @ApiOperation("题目列表-创建题目")
    @PostMapping("/create")
    public CommonResult<Integer> create(@RequestBody StudyQuestions studyQuestions) {
       return CommonResult.success(studyQuestionsService.addStudyQuestions(studyQuestions));
    }

    @ApiOperation("题目列表-根据id获取试题")
    @GetMapping("/getStudyQuestions/{id}")
    public CommonResult<StudyQuestions> getStudyQuestions(@PathVariable("id") Integer id) {
        return CommonResult.success(studyQuestionsService.getStudyQuestions(id));
    }

    @ApiOperation("题目列表-更新试题")
    @PutMapping("/update")
    public CommonResult<Integer> update(@RequestBody StudyQuestions studyQuestions) {
        return CommonResult.success(studyQuestionsService.updateStudyQuestions(studyQuestions));
    }

    @ApiOperation("题目列表-删除试题")
    @DeleteMapping("/delete/{id}")
    public CommonResult<Integer> delete(@PathVariable("id") Integer id) {
        return CommonResult.success(studyQuestionsService.deleteStudyQuestions(id));
    }


    @ApiOperation("题目列表-批量删除试题")
    @DeleteMapping("/deleteList")
    public CommonResult<Integer> deleteList(@RequestBody Integer[] ids) {
        return CommonResult.success(studyQuestionsService.deleteStudyQuestionsByIds(ids));
    }

}
